/**
 * Debug utility for DataSource Management page
 * Helps verify the fixes are working correctly
 */

export const debugDataSourcePage = async () => {
  console.log('🔍 DataSource Management Page Debug Info:');

  // Check if requestGuard is available and has correct methods
  try {
    const { requestGuard } = await import('./requestGuard');
    console.log('✅ requestGuard imported successfully');
    
    // Check available methods
    const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(requestGuard));
    console.log('📋 Available requestGuard methods:', methods);
    
    // Test clearGuard method
    if (typeof requestGuard.clearGuard === 'function') {
      console.log('✅ clearGuard method is available');
      requestGuard.clearGuard('test-key');
      console.log('✅ clearGuard method works');
    } else {
      console.error('❌ clearGuard method not found');
    }
    
    // Test canRequest method
    if (typeof requestGuard.canRequest === 'function') {
      console.log('✅ canRequest method is available');
      const canRequest = requestGuard.canRequest('test-key', { test: true });
      console.log('✅ canRequest method works, result:', canRequest);
    } else {
      console.error('❌ canRequest method not found');
    }
    
    // Test completeRequest method
    if (typeof requestGuard.completeRequest === 'function') {
      console.log('✅ completeRequest method is available');
      requestGuard.completeRequest('test-key');
      console.log('✅ completeRequest method works');
    } else {
      console.error('❌ completeRequest method not found');
    }
    
  } catch (error) {
    console.error('❌ Error importing requestGuard:', error);
  }
  
  // Check if useAuth hook is working
  try {
    console.log('🔍 Checking useAuth availability...');
    // This would need to be called from within a React component
    console.log('ℹ️ useAuth check needs to be done from within React component');
  } catch (error) {
    console.error('❌ Error with useAuth:', error);
  }
  
  console.log('🎯 Debug complete');
};

// Auto-run in development
if (process.env.NODE_ENV === 'development') {
  // Delay execution to ensure modules are loaded
  setTimeout(async () => {
    await debugDataSourcePage();
  }, 1000);
}

export default debugDataSourcePage;
